package cn.stylefeng.guns.sys.modular.system.service;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.SysCompany;
import cn.stylefeng.guns.sys.modular.system.mapper.SysCompanyMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.SysCompanyParam;
import cn.stylefeng.guns.sys.modular.system.model.result.SysCompanyResult;
import  cn.stylefeng.guns.sys.modular.system.service.SysCompanyService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 核算主体表 服务实现类
 * </p>
 *
 * @author wzh
 * @since 2024-01-08
 */
@Service
public class SysCompanyService extends ServiceImpl<SysCompanyMapper, SysCompany> {


    public void add(SysCompanyParam param){
        SysCompany entity = getEntity(param);
        this.save(entity);
    }


    public void delete(SysCompanyParam param){
        this.removeById(getKey(param));
    }


    public void update(SysCompanyParam param){
        SysCompany oldEntity = getOldEntity(param);
        SysCompany newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }


    public SysCompanyResult findBySpec(SysCompanyParam param){
        return null;
    }


    public List<SysCompanyResult> findListBySpec(SysCompanyParam param){
        return null;
    }


    public LayuiPageInfo findPageBySpec(SysCompanyParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(SysCompanyParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private SysCompany getOldEntity(SysCompanyParam param) {
        return this.getById(getKey(param));
    }

    private SysCompany getEntity(SysCompanyParam param) {
        SysCompany entity = new SysCompany();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    @Autowired
    private SysCompanyMapper sysCompanyMapper;
    public List<SysCompanyResult> list2( SysCompanyParam sysCompanyParam) {
        List<SysCompanyResult> list = sysCompanyMapper.List2(sysCompanyParam);
        return list;
    }
}
